package com.x.component.hardware;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class CpuFrequencyReader {

	private static String readCpuFrequency(String type) {
		String path = "/sys/devices/system/cpu/cpu4/cpufreq/" + type;
		try (BufferedReader br = new BufferedReader(new FileReader(path))) {
			String line = br.readLine();
			if (line != null) {
				return line.trim();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return "Unavailable";
	}

	public static String readCurrentCpuFrequency() {
		return readCpuFrequency("scaling_cur_freq");
	}

	public static String readMaxCpuFrequency() {
		return readCpuFrequency("scaling_max_freq");
	}

	public static String readMinCpuFrequency() {
		return readCpuFrequency("scaling_min_freq");
	}

	public static String readFileSystem(String path) {
		try (BufferedReader br = new BufferedReader(new FileReader(path))) {
			String line = br.readLine();
			if (line != null) {
				return line.trim();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return "";
	}
}
